//计算每个点位时间与总时间
// pArr:[{x,y,z}]
// speed number
export const getSiteTimes = (pArr, speed) => {
  let timeSum = 0
  let times = []
  for (var i = 0; i < pArr.length; i++) {
      if (i == 0) {
        times.push(0); //第0个时间为0
        continue;
      }
      
      // 计算总时间
      timeSum += spaceDistance([pArr[i - 1], pArr[i]]) / speed;
      // 将每段距离所用的时间收集起来
      times.push(timeSum);
  }
  return {
      timeSum: timeSum,
      siteTimes: times,
  };
};

//计算距离
export const spaceDistance = (positions) => {
  let distance = 0;
  for (let i = 0; i < positions.length - 1; i++) {
    let s = Cesium.Cartesian3.distance(positions[i], positions[i + 1])
    distance = distance + s;
  }
  return distance.toFixed(2);
};